package com.xyhuo.leetcode.january;

/**
 * 只出现一次的数字
 * https://leetcode.cn/problems/single-number-ii/
 *
 * @time 2024/1/17
 */
public class SingleNumberSecond {

//    public static void main(String[] args) {
//        SingleNumberSecond sns = new SingleNumberSecond();
//        int[] nums = {2, 2, 3, 2};
//        sns.singleNumber(nums);
//    }

    public int singleNumber(int[] nums) {
        int ans = 0;
        for (int i = 0; i < 32; ++i) {
            int total = 0;
            for (int num : nums) {
                total += ((num >> i) & 1);
            }
            if (total % 3 != 0) {
                ans |= (1 << i);
            }
        }
        return ans;
    }

}
